/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY. 
 * See the GNU General Public License for more details.
 * 
 * Copyright (C) 2011 CellObject.net
 */
package net.cellobject.javacodeformatter.handler;

import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.ui.actions.WorkspaceModifyOperation;

public class DeleteResourceOperation extends WorkspaceModifyOperation {
	private final IResource[] resources;

	public DeleteResourceOperation(final IResource[] resources) {
		this.resources = resources;
	}

	@Override
	protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
		monitor.beginTask("Deleting resources...", resources.length);
		for (final IResource resource : resources) {
			if (monitor.isCanceled()) {
				break;
			}
			resource.delete(true, new SubProgressMonitor(monitor, 1));
		}
		monitor.done();
	}
}
